﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace hse_2013_games
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        SoundPlayer won = new SoundPlayer("../../won.wav");
        SoundPlayer lose = new SoundPlayer("../../lose.wav");

        Image krest = Image.FromFile("../../images.jpg");
        Image nol = Image.FromFile("../../nol.png");
        int ocher = 1;
        int[,] mas = new int[3, 3];
        int prov = 0;
        int shag = 0;
        int[,] komp = new int[3, 3];
        Random a = new Random();
        int n, m;
        private void button1_Click(object sender, EventArgs e)
        {
            if (ocher == 1 && radioButton2.Checked == true)
            {
                button1.Image = krest;
                ocher = 2;
                mas[0, 0] = 1;
                shag++;
                button1.Enabled = false;
            }
            else
            {
                button1.Image = nol;
                ocher = 1;
                mas[0, 0] = 2;
                shag++;
                button1.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button1.Image = krest;
                mas[0, 0] = 1;
                komp[0, 0] = 1;
                button1.Enabled = false;

                /* for (int i = 0; i < 3; i++)
                 {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;

                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button2.Image = krest;
                ocher = 2;
                mas[0, 1] = 1;
                shag++;
                button2.Enabled = false;
            }
            else
            {
                button2.Image = nol;
                ocher = 1;
                mas[0, 1] = 2;
                shag++;
                button2.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button2.Image = krest;
                mas[0, 1] = 1;
                komp[0, 1] = 1;
                button2.Enabled = false;
                /* for (int i = 0; i < 3; i++)
                {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button3.Image = krest;
                ocher = 2;
                mas[0, 2] = 1;
                shag++;
                button3.Enabled = false;
            }
            else
            {
                button3.Image = nol;
                ocher = 1;
                mas[0, 2] = 2;
                shag++;
                button3.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button3.Image = krest;
                mas[0, 2] = 1;
                komp[0, 2] = 1;
                button3.Enabled = false;
                /* for (int i = 0; i < 3; i++)
                  {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button4.Image = krest;
                ocher = 2;
                mas[1, 0] = 1;
                shag++;
                button4.Enabled = false;
            }
            else
            {
                button4.Image = nol;
                ocher = 1;
                mas[1, 0] = 2;
                shag++;
                button4.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button4.Image = krest;
                mas[1, 0] = 1;
                komp[1, 0] = 1;
                button4.Enabled = false;
                /* for (int i = 0; i < 3; i++)
                 {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button5.Image = krest;
                ocher = 2;
                mas[1, 1] = 1;
                shag++;
                button5.Enabled = false;
            }
            else
            {
                button5.Image = nol;
                ocher = 1;
                mas[1, 1] = 2;
                shag++;
                button5.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button5.Image = krest;
                mas[1, 1] = 1;
                komp[1, 1] = 1;
                button5.Enabled = false;
                /* for (int i = 0; i < 3; i++)
                  {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button6.Image = krest;
                ocher = 2;
                mas[1, 2] = 1;
                shag++;
                button6.Enabled = false;
            }
            else
            {
                button6.Image = nol;
                ocher = 1;
                mas[1, 2] = 2;
                shag++;
                button6.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button6.Image = krest;
                mas[1, 2] = 1;
                komp[1, 2] = 1;
                button6.Enabled = false;
                /* for (int i = 0; i < 3; i++)
               {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button7.Image = krest;
                ocher = 2;
                mas[2, 0] = 1;
                shag++;
                button7.Enabled = false;
            }
            else
            {
                button7.Image = nol;
                ocher = 1;
                mas[2, 0] = 2;
                shag++;
                button7.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button7.Image = krest;
                mas[2, 0] = 1;
                komp[2, 0] = 1;
                button7.Enabled = false;
                /* for (int i = 0; i < 3; i++)
                 {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button8.Image = krest;
                ocher = 2;
                mas[2, 1] = 1;
                shag++;
                button8.Enabled = false;
            }
            else
            {
                button8.Image = nol;
                ocher = 1;
                mas[2, 1] = 2;
                shag++;
                button8.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button8.Image = krest;
                mas[2, 1] = 1;
                komp[2, 1] = 1;
                button8.Enabled = false;
                /* for (int i = 0; i < 3; i++)
               {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 2) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 2) { button9.Image = nol; button9.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }

                }
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (ocher == 1)
            {
                button9.Image = krest;
                ocher = 2;
                mas[2, 2] = 1;
                shag++;
                button9.Enabled = false;
            }
            else
            {
                button9.Image = nol;
                ocher = 1;
                mas[2, 2] = 2;
                shag++;
                button9.Enabled = false;
            }
            if (radioButton1.Checked == true)
            {
                button9.Image = krest;
                mas[2, 2] = 1;
                komp[2, 2] = 1;
                button9.Enabled = false;
                /*for (int i = 0; i < 3; i++)
                 {*/
                for (int j = 0; j < 9; j++)
                {
                    n = a.Next(0, 3);
                    m = a.Next(0, 3);
                    if (komp[n, m] != 1)
                    {
                        komp[n, m] = 1;
                        if (n == 0 && m == 0) { button1.Image = nol; button1.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 0 && m == 1) { button2.Image = nol; button2.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 0) { button4.Image = nol; button4.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 1) { button5.Image = nol; button5.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 1 && m == 2) { button6.Image = nol; button6.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button7.Image = nol; button7.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 1) { button8.Image = nol; button8.Enabled = false; shag++; mas[n, m] = 2; break; }
                        if (n == 2 && m == 0) { button3.Image = nol; button3.Enabled = false; shag++; mas[n, m] = 2; break; }
                        break;
                    }


                }
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (mas[0, 0] == 1 && mas[0, 1] == 1 && mas[0, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;

            }
            if (mas[0, 2] == 1 && mas[1, 2] == 1 && mas[2, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[1, 0] == 1 && mas[1, 1] == 1 && mas[1, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 0] == 1 && mas[1, 0] == 1 && mas[2, 0] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[2, 0] == 1 && mas[1, 1] == 1 && mas[0, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 1] == 1 && mas[1, 1] == 1 && mas[2, 1] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[2, 0] == 1 && mas[2, 1] == 1 && mas[2, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 0] == 1 && mas[1, 1] == 1 && mas[2, 2] == 1)
            {
                label1.Text = "Конец игры, крестики победили!!!";
                if (radioButton1.Checked == true)
                {
                    won.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 0] == 2 && mas[1, 1] == 2 && mas[2, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[1, 0] == 2 && mas[1, 1] == 2 && mas[1, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[2, 0] == 2 && mas[2, 1] == 2 && mas[2, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[2, 0] == 2 && mas[1, 1] == 2 && mas[0, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 0] == 2 && mas[1, 0] == 2 && mas[2, 0] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 0] == 2 && mas[0, 1] == 2 && mas[0, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (mas[0, 1] == 2 && mas[1, 1] == 2 && mas[2, 1] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }

            if (mas[0, 2] == 2 && mas[1, 2] == 2 && mas[2, 2] == 2)
            {
                label1.Text = "Конец игры, нолики победили!!!";
                if (radioButton1.Checked == true)
                {
                    lose.PlaySync();
                    timer1.Stop();
                }
                button10.Visible = true;
                prov = 1;
                goto kon;
            }
            if (prov == 0 && shag == 9)
            {
                label1.Text = "Ничья";
                button10.Visible = true;
            }
        kon:
            if (prov == 1)
            {
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
                button4.Enabled = false;
                button5.Enabled = false;
                button6.Enabled = false;
                button7.Enabled = false;
                button8.Enabled = false;
                button9.Enabled = false;
            }

            this.Refresh();
        }
        private void button10_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
            button5.Enabled = true;
            button6.Enabled = true;
            button7.Enabled = true;
            button8.Enabled = true;
            button9.Enabled = true;
            radioButton1.Enabled = false;

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
            button5.Enabled = true;
            button6.Enabled = true;
            button7.Enabled = true;
            button8.Enabled = true;
            button9.Enabled = true;
            radioButton2.Enabled = false;

        }

        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.FillRectangle(Brushes.LightBlue, 10, 20, 105, 110);
            Pen lin = new Pen(Color.Black, 2);
            e.Graphics.DrawLine(lin, 10, 20, 10, 130);
            e.Graphics.DrawLine(lin, 44, 20, 44, 130);
            e.Graphics.DrawLine(lin, 82, 20, 82, 130);
            e.Graphics.DrawLine(lin, 115, 20, 115, 130);
            e.Graphics.DrawLine(lin, 10, 20, 114, 20);
            e.Graphics.DrawLine(lin, 10, 53, 114, 53);
            e.Graphics.DrawLine(lin, 10, 96, 114, 96);
            e.Graphics.DrawLine(lin, 10, 130, 114, 130);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            this.UpdateStyles();
        }
    }

}
